<%-- 
    Document   : indexManterProduto
    Created on : 15/10/2011, 16:57:51
    Author     : Junior JAFJ
--%>

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" trimDirectiveWhitespaces="true"%>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<tiles:insertTemplate template="/WEB-INF/template/template001.jsp" flush="true" >

    <tiles:putAttribute name="title" cascade="true">Portfull</tiles:putAttribute>
    <tiles:putAttribute name="keywords" cascade="true">dinheiro, publicidade</tiles:putAttribute>
    <tiles:putAttribute name="description" cascade="true">ganhe dinheiro</tiles:putAttribute>

    <tiles:putAttribute name="css_extension" cascade="true">
        <%--link rel="stylesheet" type="text/css" href="<c:url value="/css/home.css"/>" /--%>
    </tiles:putAttribute>
    <tiles:putAttribute name="js_extension" cascade="true">
        <script charset="utf-8" type="text/javascript" />
        //<![CDATA[
            jQuery(document).ready(function() {
            
               $('#btnGravar').click (
                    function () {
                        var valores = "servicoDTO.nome=" + $('#nome').val() +
                                      "&servicoDTO.preco=" + $('#preco').val() +
                                      "&servicoDTO.strClassificacaoLivre=" + $('#classificacaoSelecionado').val() +
                                      "&servicoDTO.descricao=" + $('#descricao').val() +
                                      "&servicoDTO.periodoCriacao=" + $('#periodoCriacao').val();
                        $.ajax({
                          url: "<c:url value="/rest/servicoDesign/"/>",
                          dataType:"json",
                          type:"POST",
                          data:"" + valores,
                          success: function(data, textStatus, jqXHR){
                            alert(data + " - " + textStatus);
                          }
                        });
                    }
               );

               $('#btnAlterar').click (
                    function () {
                        var valores = "servicoDTO.nome=" + $('#nome').val() +
                                  "&servicoDTO.preco=" + $('#preco').val() +
                                  "&servicoDTO.strClassificacaoLivre=" + $('#classificacaoSelecionado').val() +
                                  "&servicoDTO.descricao=" + $('#descricao').val() +
                                  "&servicoDTO.periodoCriacao=" + $('#periodoCriacao').val() +
                                  "&_method=PUT";
                        $.ajax({
                          url: "<c:url value='/rest/servicoDesign/'/>" + $('#id').val(),
                          dataType:"json",
                          type:"POST",
                          data:"" + valores,
                          success: function(data, textStatus, jqXHR){
                            alert(data + " - " + textStatus);
                          }
                        });                 
                    }
               );

               $('#btnExcluir').click (
                    function () {
                        var valores = "_method=Delete";
                        $.ajax({
                          url: "<c:url value='/rest/servicoDesign/'/>" + $('#id').val(),
                          dataType:"json",
                          type:"POST",
                          data:"" + valores,
                          success: function(data, textStatus, jqXHR){
                            alert(data + " - " + textStatus);
                          }
                        });
                    }
               );

               $('#btnPesquisar').click (
                    function () {
                        var valores = "_method=GET";
                        $.ajax({
                          url: "<c:url value='/rest/servicoDesign/'/>" + $('#filtroNome').val(),
                          dataType:"json",
                          type:"POST",
                          data:"" + valores,
                          success: function(data, textStatus, jqXHR){
                            document.forms[0].listaServico.value = data;
                            // alert(document.forms[0].listaServico.value + " - " + textStatus);
                          }
                        });
                    }
               );

               $('#btnDetalhar').click (
                    function () {
                        var valores = "_method=POST";
                        $.ajax({
                          url: "<c:url value='/rest/servicoDesign/'/>" + $('#id').val(),
                          dataType:"json",
                          type:"POST",
                          data:"" + valores,
                          success: function(data, textStatus, jqXHR){
                            document.forms[0].servDetalhado.value = data;
                            //alert(document.forms[0].servDetalhado.value + " - " + textStatus);
                          }
                        });
                    }
               );

          });

        function selecaoAtiva(obj) {
            document.forms[0].elements['classificacaoSelecionado'].value = obj.value;
        }
        //]]>

        </script>
    </tiles:putAttribute>

    <tiles:putAttribute name="aside" cascade="true">
        <pre>Aside - Portfull!!!</pre>
    </tiles:putAttribute>
    
    <tiles:putAttribute name="content" cascade="true">
        <pre>Section - Portfull!!!</pre>
        <form id="persist" method="POST" action="<c:url value="/rest/servicoDesign/"/>">
            <input type="hidden" name="_method" value="POST"/>
            <input type="hidden" name="servDetalhado" value=""/>
            <input type="hidden" name="listaServico" value=""/>
            <input type="hidden" id="classificacaoSelecionado" value="Sim"/>

            Id: <input type="text" name="servicoDTO.id" id="id" value=""/><br />
            Nome: <input type="text" name="servicoDTO.nome" id="nome" value=""/><br />
            Preço: <input type="text" name="servicoDTO.preco" id="preco" value=""/><br />
            Descrição: <input type="text" name="servicoDTO.descricao" id="descricao" value=""/><br />
            Classificação Livre <br />
            <input type="radio" name="servicoDTO.strClassificacaoLivre" value="sim" onclick="selecaoAtiva(this)" checked>Sim<br />
            <input type="radio" name="servicoDTO.strClassificacaoLivre" value="nao" onclick="selecaoAtiva(this)">Não <br />
            Período criação: <input type="text" name="servicoDTO.periodoCriacao" id="periodoCriacao" value=""/><br />
            Filtro pesquisa nome: <input type="text" name="servicoDTO.filtroNome" id="filtroNome" value=""/><br />
        </form>
        <input type="button" value="Gravar" id="btnGravar" />
        <input type="button" value="Alterar" id="btnAlterar" />
        <input type="button" value="Excluir" id="btnExcluir" />
        <input type="button" value="Pesquisar" id="btnPesquisar" />
        <input type="button" value="Detalhar" id="btnDetalhar" />
    </tiles:putAttribute>

</tiles:insertTemplate>
